package com.zide.framework.config.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

/**
 * @author ShiTian
 * @date 2022/7/15 11:55
 */
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        LocalDateTime currentDateTime = LocalDateTime.now();
        this.strictInsertFill(metaObject, "createTime", () -> currentDateTime, LocalDateTime.class); // 起始版本 3.3.3(推荐)
        this.strictUpdateFill(metaObject, "updateTime", () -> currentDateTime, LocalDateTime.class); // 起始版本 3.3.3(推荐)


    }

    @Override
    public void updateFill(MetaObject metaObject) {
        LocalDateTime currentDateTime = LocalDateTime.now();
        this.strictUpdateFill(metaObject, "updateTime", () -> currentDateTime, LocalDateTime.class); // 起始版本 3.3.3(推荐)
    }
}

